home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / cfb / cfbsetsp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-15  |  7.2 KB  |  267 lines

  1. /***********************************************************
  2. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. #include "X.h"
  26. #include "Xmd.h"
  27. #include "servermd.h"
  28.  
  29. #include "misc.h"
  30. #include "regionstr.h"
  31. #include "gcstruct.h"
  32. #include "windowstr.h"
  33. #include "pixmapstr.h"
  34. #include "scrnintstr.h"
  35.  
  36. #include "cfb.h"
  37. #include "cfbmskbits.h"
  38.  
  39.  
  40. /* cfbSetScanline -- copies the bits from psrc to the drawable starting at
  41.  * (xStart, y) and continuing to (xEnd, y).  xOrigin tells us where psrc 
  42.  * starts on the scanline. (I.e., if this scanline passes through multiple
  43.  * boxes, we may not want to start grabbing bits at psrc but at some offset
  44.  * further on.) 
  45.  */
  46. cfbSetScanline(y, xOrigin, xStart, xEnd, psrc, alu, pdstBase, widthDst, planemask)
  47.     int            y;
  48.     int            xOrigin;    /* where this scanline starts */
  49.     int            xStart;        /* first bit to use from scanline */
  50.     int            xEnd;        /* last bit to use from scanline + 1 */
  51.     register int    *psrc;
  52.     register int    alu;        /* raster op */
  53.     int            *pdstBase;    /* start of the drawable */
  54.     int            widthDst;    /* width of drawable in words */
  55.     unsigned long    planemask;
  56. {
  57.     int            w;        /* width of scanline in bits */
  58.     register int    *pdst;        /* where to put the bits */
  59.     register int    tmpSrc;        /* scratch buffer to collect bits in */
  60.     int            dstBit;        /* offset in bits from beginning of 
  61.                      * word */
  62.     register int    nstart;     /* number of bits from first partial */
  63.     register int    nend;         /* " " last partial word */
  64.     int            offSrc;
  65.     int        startmask, endmask, nlMiddle, nl;
  66.  
  67.     pdst = pdstBase + (y * widthDst) + (xStart >> PWSH); 
  68.     psrc += (xStart - xOrigin) >> PWSH;
  69.     offSrc = (xStart - xOrigin) & PIM;
  70.     w = xEnd - xStart;
  71.     dstBit = xStart & PIM;
  72.  
  73.     if (dstBit + w <= PPW) 
  74.     { 
  75.     getbits(psrc, offSrc, w, tmpSrc);
  76.     putbitsrop(tmpSrc, dstBit, w, pdst, planemask, alu); 
  77.     } 
  78.     else 
  79.     { 
  80.  
  81.     maskbits(xStart, w, startmask, endmask, nlMiddle);
  82.     if (startmask) 
  83.         nstart = PPW - dstBit; 
  84.     else 
  85.         nstart = 0; 
  86.     if (endmask) 
  87.         nend = xEnd & PIM; 
  88.     else 
  89.         nend = 0; 
  90.     if (startmask) 
  91.     { 
  92.         getbits(psrc, offSrc, nstart, tmpSrc);
  93.         putbitsrop(tmpSrc, dstBit, nstart, pdst, planemask, alu);
  94.         pdst++; 
  95.         offSrc += nstart;
  96.         if (offSrc > PLST)
  97.         {
  98.         psrc++;
  99.         offSrc -= PPW;
  100.         }
  101.     } 
  102.     nl = nlMiddle; 
  103.     while (nl--) 
  104.     { 
  105.         getbits(psrc, offSrc, PPW, tmpSrc);
  106.         putbitsrop(tmpSrc, 0, PPW, pdst, planemask, alu );
  107.         pdst++; 
  108.         psrc++; 
  109.     } 
  110.     if (endmask) 
  111.     { 
  112.         getbits(psrc, offSrc, nend, tmpSrc);
  113.         putbitsrop(tmpSrc, 0, nend, pdst, planemask, alu);
  114.     } 
  115.      
  116.     } 
  117. }
  118.  
  119.  
  120.  
  121. /* SetSpans -- for each span copy pwidth[i] bits from psrc to pDrawable at
  122.  * ppt[i] using the raster op from the GC.  If fSorted is TRUE, the scanlines
  123.  * are in increasing Y order.
  124.  * Source bit lines are server scanline padded so that they always begin
  125.  * on a word boundary.
  126.  */ 
  127. void
  128. cfbSetSpans(pDrawable, pGC, psrc, ppt, pwidth, nspans, fSorted)
  129.     DrawablePtr        pDrawable;
  130.     GCPtr        pGC;
  131.     int            *psrc;
  132.     register DDXPointPtr ppt;
  133.     int            *pwidth;
  134.     int            nspans;
  135.     int            fSorted;
  136. {
  137.     int         *pdstBase;    /* start of dst bitmap */
  138.     int         widthDst;    /* width of bitmap in words */
  139.     register BoxPtr     pbox, pboxLast, pboxTest;
  140.     register DDXPointPtr pptLast;
  141.     int         alu;
  142.     RegionPtr         prgnDst;
  143.     int            xStart, xEnd;
  144.     int            yMax;
  145.  
  146.     alu = pGC->alu;
  147.     prgnDst = ((cfbPrivGC *)(pGC->devPrivates[cfbGCPrivateIndex].ptr))->pCompositeClip;
  148.  
  149.     pptLast = ppt + nspans;
  150.  
  151.     if (pDrawable->type == DRAWABLE_WINDOW)
  152.     {
  153.     pdstBase = (int *)
  154.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  155.     widthDst = (int)
  156.            ((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind
  157.             >> 2;
  158.     }
  159.     else
  160.     {
  161.     pdstBase = (int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  162.     widthDst = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  163.     }
  164.     yMax = (int) pDrawable->y + (int) pDrawable->height;
  165.  
  166.     pbox = REGION_RECTS(prgnDst);
  167.     pboxLast = pbox + REGION_NUM_RECTS(prgnDst);
  168.  
  169.     if(fSorted)
  170.     {
  171.     /* scan lines sorted in ascending order. Because they are sorted, we
  172.      * don't have to check each scanline against each clip box.  We can be
  173.      * sure that this scanline only has to be clipped to boxes at or after the
  174.      * beginning of this y-band 
  175.      */
  176.     pboxTest = pbox;
  177.     while(ppt < pptLast)
  178.     {
  179.         pbox = pboxTest;
  180.         if(ppt->y >= yMax)
  181.         break;
  182.         while(pbox < pboxLast)
  183.         {
  184.         if(pbox->y1 > ppt->y)
  185.         {
  186.             /* scanline is before clip box */
  187.             break;
  188.         }
  189.         else if(pbox->y2 <= ppt->y)
  190.         {
  191.             /* clip box is before scanline */
  192.             pboxTest = ++pbox;
  193.             continue;
  194.         }
  195.         else if(pbox->x1 > ppt->x + *pwidth) 
  196.         {
  197.             /* clip box is to right of scanline */
  198.             break;
  199.         }
  200.         else if(pbox->x2 <= ppt->x)
  201.         {
  202.             /* scanline is to right of clip box */
  203.             pbox++;
  204.             continue;
  205.         }
  206.  
  207.         /* at least some of the scanline is in the current clip box */
  208.         xStart = max(pbox->x1, ppt->x);
  209.         xEnd = min(ppt->x + *pwidth, pbox->x2);
  210.         cfbSetScanline(ppt->y, ppt->x, xStart, xEnd, psrc, alu,
  211.             pdstBase, widthDst, pGC->planemask);
  212.         if(ppt->x + *pwidth <= pbox->x2)
  213.         {
  214.             /* End of the line, as it were */
  215.             break;
  216.         }
  217.         else
  218.             pbox++;
  219.         }
  220.         /* We've tried this line against every box; it must be outside them
  221.          * all.  move on to the next point */
  222.         ppt++;
  223.         psrc += PixmapWidthInPadUnits(*pwidth, PSZ);
  224.         pwidth++;
  225.     }
  226.     }
  227.     else
  228.     {
  229.     /* scan lines not sorted. We must clip each line against all the boxes */
  230.     while(ppt < pptLast)
  231.     {
  232.         if(ppt->y >= 0 && ppt->y < yMax)
  233.         {
  234.         
  235.         for(pbox = REGION_RECTS(prgnDst); pbox< pboxLast; pbox++)
  236.         {
  237.             if(pbox->y1 > ppt->y)
  238.             {
  239.             /* rest of clip region is above this scanline,
  240.              * skip it */
  241.             break;
  242.             }
  243.             if(pbox->y2 <= ppt->y)
  244.             {
  245.             /* clip box is below scanline */
  246.             pbox++;
  247.             break;
  248.             }
  249.             if(pbox->x1 <= ppt->x + *pwidth &&
  250.                pbox->x2 > ppt->x)
  251.             {
  252.             xStart = max(pbox->x1, ppt->x);
  253.             xEnd = min(pbox->x2, ppt->x + *pwidth);
  254.             cfbSetScanline(ppt->y, ppt->x, xStart, xEnd, psrc, alu,
  255.                 pdstBase, widthDst, pGC->planemask);
  256.             }
  257.  
  258.         }
  259.         }
  260.     psrc += PixmapWidthInPadUnits(*pwidth, PSZ);
  261.     ppt++;
  262.     pwidth++;
  263.     }
  264.     }
  265. }
  266.  
  267.